#@embedLayout()


#define content()

<form id="formId" method="post">
    <input type="hidden" id="id" name="user.user_id" value="#(user.userId??)">
    <table class="table table-bordered">
        <tr>
            <td style="padding-top:15px;">#(_res.get('user.form.username')):</td>
            <td>
                <input type="text" id="userName" name="user.user_name" class="easyui-textbox"
                       data-options="required:true,validType:{username:''}" value="#(user.user_name??)" #if(user
                       !=null)readonly="readonly"#end>
            </td>
            <td style="padding-top:15px;">#(_res.get('user.form.email')):</td>
            <td>
                <input type="text" class="easyui-textbox" id="email" name="user.email"
                       data-options="required:true,validType:{email:'',length:[0,120]}" value="#(user.email??)">
            </td>
        </tr>
        #if(user == null)
        <tr>
            <td style="padding-top:15px;">#(_res.get('user.form.password')):</td>
            <td>
                <input type="text" id="pwd" name="user.pwd" class="easyui-passwordbox"
                       data-options="required:true,validType:{length:[6,32],password:''}">
            </td>
            <td style="padding-top:15px;">#(_res.get('user.form.confirmpassword')):</td>
            <td>
                <input type="text" class="easyui-passwordbox" id="confirmPassword" name="confirmPassword"
                       data-options="required:true,validType:{length:[6,32],same:['pwd']},password:''">
            </td>
        </tr>
        #end
        <tr>
            <td style="padding-top:15px;">#(_res.get('user.form.phone')):</td>
            <td>
                <input type="text" id="phone" name="user.phone" class="easyui-numberbox"
                       data-options="required:true,validType:'mobile'" value="#(user.phone??)">
            </td>
            <td>#(_res.get('facet.form.tenantid')):</td>
            <td>
                <select name="user.tenant_id" id="tenantId">
                </select>
            </td>
        </tr>
        <tr>
            <td style="padding-top:15px;">#(_res.get('user.form.institution')):</td>
            <td colspan="3" style="padding-top:12px;">
                <input type="text" id="instCode" name="user.inst_code" class="easyui-textbox" style="width: 180px"
                       data-options="required:false,validType:{instCode:'',length:[0,160]},
                           prompt:'多个机构号使用英文逗号隔开'" value="#(user.inst_code??)">
            </td>
        </tr>
        <tr>
            <td style="padding-top:15px;">#(_res.get('role.form.name')):</td>
            <td colspan="3" style="padding-top:12px;">
                #for(role : roles)
                <label for="#(role.roleId)">#(role.roleName)</label>
                <input type="checkbox" name="role" id="#(role.roleId)" value="#(role.roleId)" #(role.get("ur_id") !=
                null ? "checked" :"") style="margin-right: 5px;" onchange="checkSuperManagerForRole(this)">
                #end
            </td>
        </tr>
        <tr>
            <td style="padding-top:15px;">#(_res.get('user.form.des')):</td>
            <td colspan="3" style="padding-top:12px;">
                <input type="text" class="easyui-textbox" id="des" name="user.des"
                       data-options="validType:{length:[0,300]},multiline:true" value="#(user.des??)"
                       style="width:98%;height:150px;">
            </td>
        </tr>
    </table>
</form>

#end


#define css()


#end


#define js()

<script type="text/javascript">

    $(function () {
        $("#tenantId").combobox({
            url: contextRootPath + '/tenant/listAll',
            method: 'get',
            valueField: 'tenant_id',
            textField: 'alias_name',
            panelHeight: 'auto',
            width: '90%',
            editable: false,
            multiple: true,
            multivalue: false,
            onChange: function (newValue, oldValue) {

                if (newValue.length > 0) {
                    if (newValue[0] === '') {
                        $(this).combobox('setValue', newValue.pop());
                    }
                }

                if (newValue.length > 25) {
                    $.messager.alert('警告', '每个渠道管理员不能管理超过25个渠道');
                    $(this).combobox('setValue', oldValue);
                }
            }
        }).combobox('setValue', '#(user.tenantId??)');

    });


    function datagrid_save(opr_type) {
        var url = '';
        if (opr_type == 'add') {
            url = contextRootPath + '/user/save';
        } else {
            url = contextRootPath + '/user/update';
        }

        $('#formId').form('submit', {
            url: url,
            onSubmit: function () {
                var flag = $(this).form('enableValidation').form('validate');
                if (flag) {
                    showProcess(true, '温馨提示', '正在提交数据...');

                    if (opr_type == 'add') {
                        $("#pwd").passwordbox('setValue', CryptoJS.MD5($("#pwd").passwordbox('getValue')).toString());
                        $("#confirmPassword").passwordbox('setValue', CryptoJS.MD5($("#confirmPassword").passwordbox('getValue')).toString());
                    }
                }

                return flag;
            },
            success: function (data) {
                showProcess(false);

                if (!data.flag) {
                    $("#pwd").passwordbox('setValue', '');
                    $("#confirmPassword").passwordbox('setValue', '');
                }

                var params = {};
                params.element = _datagrid;
                params.data = data;
                resultCallback(params);
            },
            onLoadError: function () {
                showProcess(false);
                $.messager.alert('温馨提示', '由于网络或服务器太忙，提交失败，请重试！');
            }
        });
    }

</script>

#end


